//
//  StatisticalManager.m
//  BaseDemo
//
//  Created by unispeed on 2019/7/11.
//  Copyright © 2019 coder. All rights reserved.
//

#import "StatisticalManager.h"
#import <Bugly/Bugly.h>

@implementation StatisticalManager

/**
 *    @brief    构建单例
 *
 *    @return    返回单例
 */
+ (id)shareInstance
{
    static dispatch_once_t once;
    Class class = [self class];
    static id instance;
    dispatch_once(&once, ^{
        instance = [[class alloc] init];
    });
    return instance;
}

- (void)startConfigAppId:(NSString*)appId;
{
    
    //错误统计
    BuglyConfig * config = [[BuglyConfig alloc] init];
#ifdef RELEASE
    config.channel = @"App Store";
#else
    config.channel = @"pgyer";
#endif
    // 设置自定义日志上报的级别，默认不上报自定义日志
    config.reportLogLevel = BuglyLogLevelError;
    [Bugly startWithAppId:appId config:config];
    
}

/**
 *  设置用户标识
 *
 *  @param userId 用户标识
 */
- (void)setUserIdentifier:(NSString *)userId;
{
    
    [Bugly setUserIdentifier:[NSString stringWithFormat:@"%@",userId]];
}


/**
 上报exception，设置用户信息dic
 */
- (void)reportException:(NSException*)exception withUserInfo:(NSDictionary*)userInfo;
{
    NSArray * keys = [userInfo allKeys];
    for (NSString * key in keys) {
        //数字类型value无法存储记录
        [Bugly setUserValue:[NSString stringWithFormat:@"%@",[userInfo objectForKey:key]] forKey:key];
    }
    
    [Bugly reportException:exception];
}


/**
 上报error，设置用户信息dic
 */
- (void)reportError:(NSError*)error withUserInfo:(NSDictionary*)userInfo andErrorInfo:(NSString*)errorInfo;
{
    NSArray * keys = [userInfo allKeys];
    for (NSString * key in keys) {
        //数字类型value无法存储记录
        [Bugly setUserValue:[NSString stringWithFormat:@"%@",[userInfo objectForKey:key]] forKey:key];
    }
    
    [Bugly reportError:error];
    [BuglyLog level:BuglyLogLevelError tag:@"116985" log:@"%@", errorInfo];
}



@end
